package com.imooc.listener;

import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class BossListener implements AsyncListener {
    final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Override
    public void onComplete(AsyncEvent event) throws IOException {
    	/*监听器中可以获取request*/
		ServletRequest suppliedRequest = event.getSuppliedRequest();
		/*监听器中可以获取response*/
		ServletResponse suppliedResponse = event.getSuppliedResponse();
		System.out.println("在" + formatter.format(new Date()) + "工作处理完成");
    }
    @Override
    public void onError(AsyncEvent event) throws IOException {
        System.out.println("在" + formatter.format(new Date()) + "工作处理出错，详情如下：\t"
            +event.getThrowable().getMessage());
    }
    @Override
    public void onStartAsync(AsyncEvent event) throws IOException {
        System.out.println("在" + formatter.format(new Date()) + "工作处理开始");
    }
    @Override
    public void onTimeout(AsyncEvent event) throws IOException {
        System.out.println("在" + formatter.format(new Date()) + "工作处理超时");
    }
}
